//
//  Footer_Button_CCell.swift
//  MikerShop
//
//  Created by eme on 2016/12/26.
//  Copyright © 2016年 eme. All rights reserved.
//

/*
 owner:cy
 update:2016年12月26日11:33:44
 info: 添加购物车的  底部按钮
 VC :  HomePageVc
 */
import UIKit
import Kingfisher
import RxSwift
import RickonCore

class Footer_Button_CCell: UICollectionViewCell {
    
     @IBOutlet weak var title_Btn : UIButton!
    private let disposeBag = DisposeBag()
    var item:Footer_Button_Model? {
        didSet {
            if let item = self.item {
                self.title_Btn.setTitle(item.title, for: .normal)
                if let bgcolor = item.backgroundColor {
                    self.title_Btn.setBackgroundImage(UIColor(hex: bgcolor).getImage(), for: .normal)
                    self.title_Btn.setBackgroundImage(UIColor(hex: item.disableColor).getImage(), for: .disabled)
                }
                if let titleColor = item.titleColor {
                    self.title_Btn.setTitleColor( UIColor(hex: titleColor), for: .normal)
                }
                if let fontSize = item.fontSize {
                    self.title_Btn.titleLabel?.font = UIFont(name: Theme.font.normal, size: fontSize)
                }
                ///表示是否可以点击
                self.title_Btn.isEnabled = item.btnIsEnable
            }
        }
    }
    var didClicked_Closure:((_ type:String) -> Void)?
    
    override func awakeFromNib() {
        self.title_Btn.backgroundColor = UIColor.clear
        self.title_Btn.rx.tap.subscribe(onNext: { [unowned self] ( _ ) in
            if let didClicked_Closure = self.didClicked_Closure{
                didClicked_Closure(self.item!.type)
            }
        }).disposed(by: disposeBag)
        
    }
}
